import 'dart:io';

class MyHttpOverrides extends HttpOverrides {
  final String host = '127.0.0.1';
  final int port = 7890;

  @override
  HttpClient createHttpClient(SecurityContext? context) {
    var client = super.createHttpClient(context);
    client.findProxy = (uri) {
      // 这里动态判断是否需要代理
      if (shouldUseProxy(uri.host)) {
        return "PROXY $host:$port";
      }
      return "DIRECT";
    };
    client.badCertificateCallback =
        (X509Certificate cert, String host, int port) => true;
    return client;
  }
}

// 你可以自定义判断逻辑，比如只对 wallhaven.cc 代理
bool shouldUseProxy(String host) {
  // 只对 wallhaven.cc 及其子域名走代理
  return host.contains('wallhaven.cc');
}
